#ifndef __CAMERA_H__
#define __CAMERA_H__
#include <iostream>
#include <opencv2/opencv.hpp>
#include <signal.h>
typedef struct CamConfigInfo
{
    int cam_index_in_vec;
    int64_t width;
    int64_t height;
    int offset_x;
    int offset_y;
    double expotime;
    int64_t gain;
    CamConfigInfo(int _camindex, int64_t _width, int64_t _height, int _offsetx, int _offsety, double _expotime, double _gain)
                    : cam_index_in_vec(_camindex), width(_width), height(_height), offset_x(_offsetx), offset_y(_offsety), expotime(_expotime), gain(_gain)
                    {
                        
                    } 

}CamConfigInfo;

class Camera
{
protected:
    std::string cam_name;
    int64_t m_roi_width=0;       ///< 感兴趣区域宽
    int64_t m_roi_height=0;      ///< 感兴趣区域高
    int64_t m_roi_offset_x=0;      ///< 水平偏移量设置     //8 //320
    int64_t m_roi_offset_y=0;      ///< 竖直偏移量设置     //6 //272
    double m_exposure_time=0; ///< 曝光时间
    int64_t m_gain=0;            ///< 增益
    bool is_colorful;          //是否支持彩色
    bool is_opened;
    std::string device_id;//相机标识, 工业相机是设备号，虚拟相机可以以文件名作为标识
    int cam_index;
public:
    Camera(std::string camera_name):cam_name(camera_name), is_opened(false){}

    ~Camera(){}


public:
    inline void configFrame(int64_t width,
                    int64_t height,
                    int offset_x,
                    int offset_y ,
                    double expotime,
                    int64_t gain)
    {
        m_roi_width = width;
        m_roi_height = height;
        m_roi_offset_x = offset_x;
        m_roi_offset_y = offset_y;
        m_exposure_time = expotime;
        m_gain = gain;
        return;
    }
    virtual int open() = 0;//打开相机

    virtual int close() = 0;//关闭相机
    
    virtual cv::Mat getFrame() = 0;//获取相机图片

    inline bool isOpen() const
    {
        return is_opened;
    }
    virtual inline std::string cameraID() const
    {
        return device_id;
    }
    inline int index()
    {
        return cam_index;
    }
    virtual int changeCamConfig(const CamConfigInfo& info) {return 0;}
};

#endif